<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //1.定义生成器函数
        function* g() {
            console.log('---生成器函数---')
            yield 1
            yield 2
            yield 3
        }
        //2.获取生成器对象
        const g1 = g()//此时没有执行

        //3.调用next方法 
        //4. 遍历生成器对象
        for (let value of g1) {
            console.log(value)
        }


    </script>
</body>

</html>